module.exports = function (sequelize, DataTypes) {

  const Class = sequelize.define('Class', {
    name: {
      type:DataTypes.STRING(50),
      unique:true
    },
    department: DataTypes.STRING(50)
  });
  Class.associate = (models)=>{
    Class.hasMany(models.student, {
      as: 'students',
      sourceKey:'name',
      foreignKey:'class'
    }),
    Class.hasMany(models.classrecord, {
      as:'classrecords',
      sourceKey:'name',
      foreignKey:'class'
    })
  }
  return Class;
}